<?php
session_start();
ob_start();
if (isset($_GET['lang'])) {

    $lang = $_GET['lang'];
} else {
    $lang = 'en';
}
include 'lang/' . $lang . '.php';
if (!isset($_SESSION['loggedin'])) {

    header('Location: login.php');
}
?>
<?php $id = $_GET['ID'];
$id_protected = htmlspecialchars($id);
?>
<?php $id = $_GET['ID'];
$id_protected = htmlspecialchars($id);
?>
<?php include 'index.php';
?>
<div id="body-wrapper">

    <div id="main-content">

        <div class="content-box">

            <?php
             include '../db/db_con.php';
            ?>
            <?php
            if (isset($_POST['updateproduct'])) {

            
             if ($_FILES["image"]["name"] != "") {


        if ($_FILES["image"]["type"] == "image/gif" || $_FILES["image"]["type"] == "image/jpeg" || $_FILES["image"]["type"] == "image/jpg" || $_FILES["image"]["type"] == "image/pjpeg") {

            move_uploaded_file($_FILES["image"]["tmp_name"], "img/upload/" . $_FILES["image"]["name"]);

            $img = "img/upload/" . $_FILES["image"]["name"];
        }else{
            echo 'no '.mysql_error();
        }
    }
                $title_ar = $_POST['title_ar'];
                $title_en = $_POST['title_en'];
                $desc_ar = $_POST['desc_ar'];
                $desc_en = $_POST['desc_en'];
                 $price = $_POST['price'];
              
                 $type = $_POST['type'];
                   if ($type == 'General'){
                       $type = '1';
                   }else{
                       $type = '0';
                   }
                $status = $_POST['status'];
                $cat = $_POST['cat'];


                $query = "UPDATE products
            set title_ar = '{$title_ar}',
            title_en = '{$title_en}',
            desc_ar = '{$desc_ar}',
            desc_en = '{$desc_en}',
            image = '{$img}',
            status = '{$status}',
            cat = {$cat},
            price = {$price},
            type = {$type}
            where id =".$id_protected." ";

                if (mysql_query($query)) {

                    echo '
		<div class="notification success png_bg">
				<a href="" class="close"><img src="resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
				<div>
				This product Updated Is Done ..
				</div>
			</div>';
                } else {
                    echo '
		 <div class="notification error png_bg">
				<a href="" class="close"><img src="resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
				<div>
				This product Updated Is Not Done ..
				</div>
			</div>';
                }
            }
            ?>

            <div class="content-box-header" id = "addProducts" >

                <h3><?= Update_Product ?></h3>

                <div class="clear"></div>

            </div> 

            <div class="content-box-content">

                <div class="tab-content default-tab" id="tab2">

                    <form action="UpdateProducts.php?type=Product&ID=<?= $id_protected ?>&lang=<?= $lang?>" method="post" name = "updateproduct" enctype="multipart/form-data">

                        <fieldset> 

                            <p>
                                <label><?= product_title_ar ?></label>
                                <input class="text-input small-input" type="text" id="small-input" name="title_ar" />
                            </p>

                            <p>
                                <label><?= product_title_en ?></label>
                                <input class="text-input small-input" type="text" id="small-input" name="title_en" />
                            </p>

                            <p>
                                <label><?= product_desc_ar ?></label>
                                <textarea class="text-input textarea wysiwyg" id="textarea" name="desc_ar" cols="79" rows="15"></textarea>
                            </p>
                            <p>
                                <label><?= product_desc_en ?></label>
                                <textarea class="text-input textarea wysiwyg" id="textarea" name="desc_en" cols="79" rows="15"></textarea>
                            </p>

                            <p>
                                <label><?= product_image ?></label>
                                <input type="file" name="image" class="small-input"/>

                            </p>

                            <p>
                                <label><?= product_status ?></label>
                                <input type="radio" name="status" value = "active" /><?= Active ?><br />
                                <input type="radio" name="status" value = "deactive" /><?= De_Active ?>
                            </p>
                             <p>
                                <label><?= price ?></label>
                               $  <input style ="width: 50px !important; " class="text-input small-input" type="text" id="small-input" name="price" />
                            </p>

                            
                            <p>
                                <label><?= product_cat ?></label>
                                <select name="cat" class="small-input">
                                    <option value="1"><?= Nokia ?></option>
                                    <option value="2"><?= Samsung ?></option>
                                    <option value="3"><?= Motorola ?></option>
                                    <option value="4"><?= SonyEricsson ?></option>
                                    <option value="5"><?= LG ?></option>
                                    <option value="6"><?= Apple ?></option>
                                    <option value="7"><?= BlackBerry ?></option>
                                   
                                </select>
                            </p>
                             <p>
                                <label><?= type ?></label>
                                <select name="type" class="small-input">
                                    <option value="1"><?= General?></option>
                                    <option value="2"><?= Special  ?></option>
                                </select>
                             </p>

                            <p>
                                <input class="button" type="submit" name = "updateproduct" value="<?= Update_Product ?>" />
                            </p>

                        </fieldset>

                        <div class="clear"></div>

                    </form>
                </div>

            </div> 

        </div> 

    </div>

</div>